package ru.st.selenium;

import static org.junit.Assert.*;

import java.net.MalformedURLException;
import java.net.URL;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class SampleSauceLabsLaunching {
	
	@Test
	public void checkWikiTopHeaderFirefox() throws MalformedURLException {
		
		WebDriver driver = new RemoteWebDriver(new URL("http://serjteplov:d0450709-c7ca-490c-a368-1609d99d43d5@ondemand.saucelabs.com:80/wd/hub"),
							DesiredCapabilities.firefox());
		driver.get("http://en.wikipedia.org/wiki/Main_Page");
		WebElement topBanner = driver.findElement(By.xpath(".//*[@id='mp-topbanner']//div[1]"));
		System.out.println( topBanner.getText());
		assertTrue (topBanner.getText().equals("Welcome to Wikipedia,"));
		driver.quit();
	}
	
	@Test
	public void checkWikiTopHeaderChrome() {
		ChromeDriver driver = new ChromeDriver();
		driver.get("http://en.wikipedia.org/wiki/Main_Page");
		WebElement topBanner = driver.findElement(By.xpath(".//*[@id='mp-topbanner']//div[1]"));
		System.out.println( topBanner.getText());
		assertTrue (topBanner.getText().equals("Welcome to Wikipedia,"));
		driver.quit();
	}

	@Test
	public void checkWikiTopHeaderIE() {
		InternetExplorerDriver driver = new InternetExplorerDriver();
		driver.get("http://en.wikipedia.org/wiki/Main_Page");
		WebElement topBanner = driver.findElement(By.xpath(".//*[@id='mp-topbanner']//div[1]"));
		System.out.println( topBanner.getText());
		assertTrue (topBanner.getText().equals("Welcome to Wikipedia,"));
		driver.quit();
	}
	
	@Test
	public void checkWikiTopHeaderPhantomJS() {
	    DesiredCapabilities capabilities = new DesiredCapabilities();
	    capabilities.setCapability("phantomjs.binary.path", 
	    		"C:/Program Files (x86)/phantomjs-1.9.7-windows/phantomjs.exe");
		WebDriver driver = new PhantomJSDriver(capabilities);
		driver.get("http://en.wikipedia.org/wiki/Main_Page");
		WebElement topBanner = driver.findElement(By.xpath(".//*[@id='mp-topbanner']//div[1]"));
		System.out.println( topBanner.getText());
		assertTrue (topBanner.getText().equals("Welcome to Wikipedia,"));
		driver.quit();
	}
}
